<template>
  <div class="container">
    <img src="https://img.ameimeika.com/h5_images/mp_images/mp_3.1.1/banner.png" class="banner_pic"
      @click.stop="role_id>1&&account_type!=5?'':toH5()">
    <div class="bgbox" v-if="list.length==0 || (role_id>1&&account_type!=5)">
      <img src="https://img.ameimeika.com/h5_images/mp_images/mp_3.1.1/bg_nothing.png" alt class="nothing">
      <div class="text">{{role_id>1&&account_type!=5?'服务商无法参与该活动':'您还没有补贴单哦'}}</div>
    </div>
    <block v-else>
      <div class="scroll_div">
        <div class="list_li" v-for="(item,index) in list" :key="index">
          <a :href="'/pages/package_mine/plus_butie/main?id='+item.allowanceId+'&isSpeed='+item.isSpeed">
            <div class="order_num">订单编号：{{item.applySn}}</div>
            <div class="order_main">
              <img class="order_pic" :src="imgUrl+item.projectImage" />
              <div class="fonts">
                <div class="title">
                  {{item.projectName}}
                  <p>{{item.hospitalName}}</p>
                </div>
                <div class="speed_bt">
                  {{item.suspend!=undefined&&item.suspend?'补贴单暂停':'第'+item.allowancedCount+'期/共'+item.applyCount+'期'}}
                  <a href="/pages/package_mine/my_subsidy/main" v-if="item.isSpeed==false">提速领补贴</a>
                </div>
              </div>
            </div>
            <div class="jf_bt">补贴单总积分：{{item.totalCredit}}积分（含可提现{{item.coin}}积分）</div>
          </a>
        </div>
      </div>
    </block>
  </div>
</template>

<script>
import common from "@/assets/js/mmk_common.js";
export default {
  data() {
    return {
      url: common.is_online
        ? "https://h5.ameimeika.com/"
        : "https://h5s.ameimeika.com/",
      imgUrl: "https://img.ameimeika.com/",
      ImgBaseUrl: "https://h5.ameimeika.com/mp_images/",
      list: [],
      role_id: 0,
      account_type: 0
    };
  },
  methods: {
    getPageData() {
      wx.showLoading({
        title: "加载中",
        mask: true
      });
      common.fly_post(
        "api/com.mmk.reservation.api.OpenUserAllowanceProvider/1.0.0/listAllowance.html",
        {},
        msg => {
          wx.hideLoading();
          let res = msg.data;
          if (res.code == 0) {
            if (!res.data) {
              return;
            }
            this.list = res.data;
          } else {
            wx.hideLoading();
            wx.showToast({
              title: res.msg,
              icon: "none",
              duration: 2000,
              mask: true
            });
            return false;
          }
        },
        "isJava"
      );
    },
    // 跳转到H5活动页
    toH5() {
      wx.redirectTo({
        url: `/pages/package_main/advertisement/main?url=${encodeURIComponent(
          this.url + "speedCard/index.html"
        )}`
      });
    }
  },

  onLoad() {
    wx.setNavigationBarTitle({
      title: "我的补贴单"
    });
    Object.assign(this.$data, this.$options.data());
    this.role_id = wx.getStorageSync("role_id")
      ? wx.getStorageSync("role_id")
      : 0;
    this.account_type = wx.getStorageSync("account_type")
      ? wx.getStorageSync("account_type")
      : 0;
    if (this.role_id > 1 && this.account_type != 5) {
      return;
    }
    this.getPageData();
  },
  onShow() {}
};
</script>

<style scoped lang="less">
.container {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  background: rgba(243, 244, 246, 1);
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  .banner_pic {
    width: 375px;
    height: 173px;
    overflow: visible;
  }
  &.bgClass {
    background-image: url("https://h5.ameimeika.com/mp_images/shouye/sousuowujieguo@2x.png");
    background-repeat: no-repeat;
    width: 100%;
    height: 100%;
    background-position: 50% 30%;
    background-size: 40%;
  }
}

.dv {
  width: 100%;
  height: 60px;
  line-height: 30px;
  box-sizing: border-box;
  color: #fff;
  background: #f3f4f6;
  /* margin-bottom: 15px; */
  padding: 15px;
}
.dv_item {
  width: auto;
  height: 30px;
  box-sizing: border-box;
  font-size: 12px;
  color: rgba(102, 102, 102, 1);
  line-height: 30px;
  padding: 0 15px;
  background: rgba(245, 231, 233, 1);
  border-radius: 15px;
  margin-right: 10px;
  float: left;
}
.active {
  box-sizing: border-box;
  border: 1px solid rgba(246, 70, 101, 1);
  color: #f64665;
}
.list {
  width: 100%;
  height: 100%;
}
.list_li {
  width: 100%;
  box-sizing: border-box;
  background: rgba(255, 255, 255, 1);
  border-radius: 10px 10px;
  padding: 11px 10px;
  margin-bottom: 10px;
}
.order_num {
  font-size: 12px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: rgba(153, 153, 153, 1);
  line-height: 16px;
  margin-bottom: 11px;
}
.order_main {
  margin-bottom: 12px;
  display: flex;
  flex-direction: row;
  .order_pic {
    width: 114px;
    height: 114px;
    border-radius: 6px;
    margin-right: 10px;
  }
  .fonts {
    flex: 1;
    .title {
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      height: 61px;
      color: rgba(51, 51, 51, 1);
      line-height: 20px;
      text-overflow: -o-ellipsis-lastline;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      line-clamp: 2;
      -webkit-box-orient: vertical;
      margin-bottom: 16px;
      p {
        font-size: 12px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: rgba(153, 153, 153, 1);
        line-height: 17px;
        -webkit-line-clamp: 1;
        line-clamp: 1;
        margin-top: 4px;
        display: block;
      }
    }
    .speed_bt {
      position: relative;
      font-size: 18px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: rgba(255, 56, 62, 1);
      line-height: 22px;
      a {
        display: block;
        font-size: 12px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: rgba(255, 255, 255, 1);
        line-height: 28px;
        width: 72px;
        height: 28px;
        background: rgba(255, 56, 62, 1);
        border-radius: 100px 0px 0px 100px;
        position: absolute;
        top: 50%;
        right: -10px;
        transform: translateY(-50%);
        text-align: center;
      }
    }
  }
}
.jf_bt {
  font-size: 12px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: rgba(102, 102, 102, 1);
  line-height: 16px;
}
.amount {
  height: 24px;
  font-size: 17px;
  font-weight: 500;
  color: #444;
  line-height: 24px;
  position: absolute;
  right: 0;
  top: 10%;
}
.tip {
  font-size: 10px;
  color: #666;
  line-height: 14px;
  position: absolute;
  right: 0;
  top: 48%;
}
.red {
  color: #ff383e;
}
.scroll_div {
  flex: 1;
  border-radius: 10px;
  width: 355px;
 margin-top: -37px;
 border-radius: 10px 10px 0px 0px;
}
.bgbox {
  background: rgba(255, 255, 255, 1);
  flex: 1;
  border-radius: 10px;
  width: 355px;
 margin-top: -37px;
 border-radius: 10px 10px 0px 0px;
  .nothing {
    width: 170px;
    height: 170px;
    margin: 172px auto 0;
    display: block;
  }
  .text {
    width: 100%;
    font-size: 12px;
    font-weight: 400;
    margin-top: 10px;
    color: rgba(153, 153, 153, 1);
    text-align: center;
  }
}
</style>

